package com.stack.article.job;

import com.stack.article.service.HotArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author llz
 * @date 2023/12/26 9:33
 * @description
 */
@Component
@Slf4j
public class WebSocketTask {

    @Resource
    private HotArticleService hotArticleService;

    /**
     * 通过WebSocket向客户端推送
     */
//    @Scheduled(cron = "0/5 * * * * ?") //每隔5秒
    @Scheduled(cron = "0 0 0/3 * * ? *") //从0时开始，每隔三个小时
    public void sendHotArticleToClient() {
        log.info("最热文章推送任务开始执行...");
        hotArticleService.sendHotArticle();
        log.info("最热文章推送任务结束...");
    }
}
